﻿#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using System.Reflection;
using System.Collections;
using System.Web;

using System.Drawing.Imaging;
using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Common.Interfaces;
using Gizmox.WebGUI.Common.Gateways;

using Gizmox.WebGUI.Forms;
using VisualWebGuiApplication2;

#endregion

namespace Gizmox.WebGuiSampleApplication
{
    public   partial class MainForm : Form
    {
        private ImageList objImageList = null;

        string selected_invoiceid = string.Empty;
        
        public MainForm()
        {
            this.Context.CurrentUICulture = new System.Globalization.CultureInfo("he-IL");
           
            this.RightToLeft = WebGUI.Forms.RightToLeft.Yes;
            bool logedin = false;
            InitializeComponent();
            tabControlMain.SelectedIndexChanged +=new EventHandler(tabControlMain_SelectedIndexChanged);
            if (null != Session["isloged"])
            {

                if ((string)Session["isloged"] == "true")
                {
                    if ((string)Session["isadmin"] == "true")
                    {
                        ManagerControl mngrctrl = new ManagerControl();
                        this.panelmanager.Controls.Add(mngrctrl);

                        Usermanagerctrl usrctrl = new Usermanagerctrl();
                        this.panelusermanage.Controls.Add(usrctrl);
                    }


                }
            }
            else
            {

                this.Context.Redirect("Login.wgx");
            }
              
           
           
            //Init RandomData
          

            //Init the buttom list
            tabControlMain_SelectedIndexChanged(null, EventArgs.Empty);

            //VWGContext.Current.CurrentTheme = "FaceBook";

            //Paint the graph
        

            objImageList = new ImageList();

            WinToWeb();

            objImageList.Images.SetKeyName(0, "Folder");
            objImageList.Images.SetKeyName(1, "Folders");
            this.treeView1.ImageList = objImageList;


            //listViewCustomers.OnSelectedIndexChanged +=new EventHandler(listViewCustomers_OnSelectedIndexChanged);
            //listViewShippers.OnSelectedIndexChanged += new EventHandler(listViewShippers_OnSelectedIndexChanged);
            //listViewProducts.OnSelectedIndexChanged += new EventHandler(listViewProducts_OnSelectedIndexChanged);
            //listViewSuppliers.OnSelectedIndexChanged += new EventHandler(listViewSuppliers_OnSelectedIndexChanged);
            //listViewOrders.OnSelectedIndexChanged += new EventHandler(listViewOrders_OnSelectedIndexChanged);
          


        }
   
        public void GoToInvoiceTab(string invoiceid, int maintabselectedindex, int toolBarindex,  int toolBarButton,int toolbarnumber)
        {
            ToolBarButtonClickEventArgs dsd=new ToolBarButtonClickEventArgs(toolBarButton1);
            this.tabControlMain.SelectedIndex = maintabselectedindex;
            this.toolBar1.TabIndex = toolBarindex;
            selected_invoiceid = invoiceid;
            if(toolBarButton==3)
            {
             dsd = new ToolBarButtonClickEventArgs(toolBarButton3);
            dsd.Button.Pushed = true;
            }
            if (toolBarButton == 1)
            {
                dsd = new ToolBarButtonClickEventArgs(toolBarButton1);
                dsd.Button.Pushed = true;
            }
            if (toolBarButton == 6)
            {
                dsd = new ToolBarButtonClickEventArgs(toolBarButton6);
                dsd.Button.Pushed = true;
            }
            if (toolBarButton == 2)
            {
                dsd = new ToolBarButtonClickEventArgs(toolBarButton2);
                dsd.Button.Pushed = true;
            }
            if (toolBarButton == 4)
            {
                dsd = new ToolBarButtonClickEventArgs(toolBarButton4);
                dsd.Button.Pushed = true;
            }
            if (toolBarButton == 5)
            {
                dsd = new ToolBarButtonClickEventArgs(toolBarButton5);
                dsd.Button.Pushed = true;
            }
            if (toolbarnumber == 1)
            {
                toolBar1_ButtonClick(toolBar1, dsd);
            }

            else
            { 
            toolBar2_ButtonClick(toolBar2, dsd);
            }
           // this.panelStockManage.Controls.Clear();


          
        
           
          /*  Usermanagerctrl usrctrl = new Usermanagerctrl();
            this.panelusermanage.Controls.Add(usrctrl);*/
         /*   TankInvoice newcontrol = new TankInvoice(invoiceid);
            //this.panelusermanage.Controls.Clear();
            this.tabPage3.Controls.Clear();
            this.tabPage3.Controls.Add(newcontrol);*/
                //()


            /*VisualWebGuiApplication2.TankInvoice objReports = new TankInvoice();
            this.panelStockManage.Controls.Add(objReports);
            this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
            this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            if(this.tabControlMain)
            this.ShowDialog();
         
            objReports.Show();*/
        }


        #region Convert

        private void WinToWeb()
        {

            InitalizeThemeMenu();

            this.tabPage1.Image = new IconResourceHandle("Contacts.gif");
            this.tabPage2.Image = new IconResourceHandle("Orders.gif");
            this.tabPage3.Image = new IconResourceHandle("employees.gif");
            this.tabPage4.Image = new IconResourceHandle("Categories.gif");
            this.tabPage5.Image = new IconResourceHandle("Products.gif");
           


            objImageList.Images.AddRange(new Gizmox.WebGUI.Common.Resources.ResourceHandle[] {
            new IconResourceHandle("Folder.gif"),
            new IconResourceHandle("Folders.gif")});
            objImageList.ImageSize = new System.Drawing.Size(16, 16);

          

   

            this.FormStyle = FormStyle.Application;
        }

        #endregion

      

        #region Tab Control

        private void tabControlMain_SelectedIndexChanged(object sender, EventArgs e)
        {
            ClearPanels();



        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            tabControlMain_SelectedIndexChanged(null, EventArgs.Empty);
        }

        #endregion
       
      

        #region Menu events

        void mainMenu1_MenuClick(object objSource, MenuItemEventArgs objArgs)
        {
            string strAction = objArgs.MenuItem.Tag as string;

            if (!string.IsNullOrEmpty(strAction))
            {


                if (strAction.StartsWith("Theme."))
                {
                    this.Context.CurrentTheme = strAction.Replace("Theme.", "");
                    UpdateThemeMenu();
                    return;
                }
            }
            else
            {
                switch (objArgs.MenuItem.Text)
                {
                    case "Show Buttom List":
                  
                        objArgs.MenuItem.Checked = !objArgs.MenuItem.Checked;
                        break;

                    case "Show Graph":
                      
                        objArgs.MenuItem.Checked = !objArgs.MenuItem.Checked;
                        break;

                    case "About":
                      /*  AboutVWGForm objAboutVWGForm = new AboutVWGForm();
                        objAboutVWGForm.ShowDialog();*/
                        break;

                    case "Exit":
                        this.Close();
                        break;

                }

            }
            
        }

        private void InitalizeThemeMenu()
        {
            menuItem24 = new MenuItem("Themes");

            foreach (string strTheme in VWGContext.Current.Config.Themes)
            {
                MenuItem objThemeMenu = new MenuItem(strTheme);
                objThemeMenu.Tag = string.Format("Theme.{0}", strTheme);
                menuItem24.MenuItems.Add(objThemeMenu);
            }

          

            UpdateThemeMenu();
        }

        private void UpdateThemeMenu()
        {
            foreach (MenuItem objMenuItem in menuItem24.MenuItems)
            {
                objMenuItem.RadioCheck = ((string)objMenuItem.Tag.ToString().Replace("Theme.", "") == VWGContext.Current.CurrentTheme);
            }
        }

        #endregion

        private void blnReorder_Click(object sender, EventArgs e)
        {

        }

        private void blnSort_Click(object sender, EventArgs e)
        {

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            if (e.Button != null)

               {

                   switch (e.Button.Style)

                   {

                       case ToolBarButtonStyle.PushButton:

                        
                           if (e.Button.Name == "toolBarButton1")
                           {    // Accompanying_stocks_open.cs
                               // show Accompanying_stocks user controls
                             //  MessageBox.Show(" show Accompanying_stocks user controls");
                               //this.panelStockManage.Controls.Clear();
                               ClearPanels();
                               VisualWebGuiApplication2.Accompanying_stocks_open objReports ;
                               if (!string.IsNullOrEmpty(selected_invoiceid))
                               {
                                   objReports = new Accompanying_stocks_open(selected_invoiceid);
                                   
                                   selected_invoiceid = string.Empty;
                               }
                               else
                               {
                                   objReports = new Accompanying_stocks_open();
                               }
                               this.panelStockManage.Controls.Add(objReports);
                               this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                               this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                           }
                           if (e.Button.Name == "toolBarButton2")
                           {
                               //tank open
                               //this.extendedListView1.LoadControl("Customers", " CustomerID , CompanyName , ContactName , ContactTitle ,Address , Country ");
                               //this.extendedListView1.SelectedIndex = 0;
                               // show Accompanying_stocks user controls
                              // this.panelStockManage.Controls.Clear();
                               ClearPanels();
                               VisualWebGuiApplication2.TabkOpen objReports;//= new TabkOpen(selected_invoiceid);

                               if (!string.IsNullOrEmpty(selected_invoiceid))
                               {
                                   objReports = new TabkOpen(selected_invoiceid);
                                   selected_invoiceid = string.Empty;
                               }
                               else
                               {
                                   objReports = new TabkOpen();
                               }
                               this.panelStockManage.Controls.Add(objReports);
                               this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                               this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                           }
                           if (e.Button.Name == "toolBarButton3")
                           {
                               // show Accompanying_stocks user controls
                               //frmTankOpen objformreport = new frmTankOpen();
                               //objformreport.ShowDialog();
                              // this.panelStockManage.Controls.Clear();
                               ClearPanels();
                               VisualWebGuiApplication2.TankInvoice objReports;
                               if (!string.IsNullOrEmpty(selected_invoiceid))
                               {
                                   objReports = new TankInvoice(selected_invoiceid);
                                   selected_invoiceid = string.Empty;
                               }
                               else
                               {
                                   objReports = new TankInvoice();
                               }
                             
                               this.panelStockManage.Controls.Add(objReports);
                               this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                               this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                           }

                           if (e.Button.Name == "toolBarButton6")
                           {
                               // show Accompanying_stocks user controls
                               //frmTankOpen objformreport = new frmTankOpen();
                               //objformreport.ShowDialog();
                               // this.panelStockManage.Controls.Clear();
                               //ClearPanels();
                               //VisualWebGuiApplication2.TankInvoiceWithMony objReports;
                               //if (!string.IsNullOrEmpty(selected_invoiceid))
                               //{
                               //    objReports = new TankInvoiceWithMony(selected_invoiceid);
                               //    selected_invoiceid = string.Empty;
                               //}
                               //else
                               //{
                               //    objReports = new TankInvoiceWithMony();
                               //}
                               
                                   
                               //this.panelStockManage.Controls.Add(objReports);
                               //this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                               //this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;

                               ClearPanels();
                               
                               if (!string.IsNullOrEmpty(selected_invoiceid))
                               {
                                  VisualWebGuiApplication2.Accompanying_stocks_open objReports = new Accompanying_stocks_open(selected_invoiceid, selected_invoiceid);

                                   selected_invoiceid = string.Empty;
                                   this.panelStockManage.Controls.Add(objReports);
                               }
                               else
                               {
                                   VisualWebGuiApplication2.TankInvoiceWithMony objReports = new TankInvoiceWithMony();
                                   this.panelStockManage.Controls.Add(objReports);
                               }
                              
                               this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                               this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;

                           }
                           break;

                       case ToolBarButtonStyle.ToggleButton:

                           MessageBox.Show(string.Format("Toggle button is turn {0}!", (e.Button.Pushed ? "on" : "off")));

                           break;

                       default:

                           MessageBox.Show(string.Format("ToolBar button '{0}' is clicked with {1} style!", e.Button.Name, e.Button.Style));

                           break;

                   }

               }
    }
        public  void ClearPanels()
        {
                this.panelStockManage.Controls.Clear();
                this.panelmanager.Controls.Clear();
                this.PanelTanFixManage.Controls.Clear();
        }
        private void toolBar2_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            if (e.Button != null)
            {

                switch (e.Button.Style)
                {

                    case ToolBarButtonStyle.PushButton:


                        if (e.Button.Name == "toolBarButton4")
                        {    // Accompanying_stocks_open.cs
                            // show Accompanying_stocks user controls
                            //  MessageBox.Show(" show Accompanying_stocks user controls");
                            ClearPanels();
                            VisualWebGuiApplication2.TabkIntegrationBeforFix objReports = new TabkIntegrationBeforFix();


                            if (!string.IsNullOrEmpty(selected_invoiceid))
                            {
                                objReports = new TabkIntegrationBeforFix(selected_invoiceid);
                                selected_invoiceid = string.Empty;
                            }
                            else
                            {
                                objReports = new TabkIntegrationBeforFix();
                            }

                            this.PanelTanFixManage.Controls.Add(objReports);
                            this.PanelTanFixManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                            this.PanelTanFixManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                        }
                        if (e.Button.Name == "toolBarButton5")
                        {
                            ClearPanels();
                            VisualWebGuiApplication2.TabkFix objReports = new TabkFix();


                            if (!string.IsNullOrEmpty(selected_invoiceid))
                            {
                                objReports = new TabkFix(selected_invoiceid);
                                selected_invoiceid = string.Empty;
                            }
                            else
                            {
                                objReports = new TabkFix();
                            }


                            this.PanelTanFixManage.Controls.Add(objReports);
                            this.PanelTanFixManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                            this.PanelTanFixManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                        }
                        if (e.Button.Name == "toolBarButton6")
                        {
                            // show Accompanying_stocks user controls
                            ClearPanels();
                            VisualWebGuiApplication2.Accompanying_stocks_open objReports;
                            if (!string.IsNullOrEmpty(selected_invoiceid))
                            {
                                objReports = new Accompanying_stocks_open(selected_invoiceid, selected_invoiceid);

                                selected_invoiceid = string.Empty;
                            }
                            else
                            {
                                objReports = new Accompanying_stocks_open();
                            }
                            this.panelStockManage.Controls.Add(objReports);
                            this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                            this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                        }
                        if (e.Button.Name == "toolBarButton1")
                        {


                            ClearPanels();
                            VisualWebGuiApplication2.TankInvoiceWithMony objReports;
                            if (!string.IsNullOrEmpty(selected_invoiceid))
                            {
                                objReports = new TankInvoiceWithMony(selected_invoiceid);
                                selected_invoiceid = string.Empty;
                            }
                            else
                            {
                                objReports = new TankInvoiceWithMony();
                            }


                            this.panelStockManage.Controls.Add(objReports);
                            this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                            this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                        }

                        break;
                        if (e.Button.Name == "toolBarButton7")
                        {
                            // show Accompanying_stocks user controls
                            MessageBox.Show("  רשימת צוברים בהמתנה");
                        }
                        break;

                    case ToolBarButtonStyle.ToggleButton:

                        MessageBox.Show(string.Format("Toggle button is turn {0}!", (e.Button.Pushed ? "on" : "off")));

                        break;

                    default:

                        MessageBox.Show(string.Format("ToolBar button '{0}' is clicked with {1} style!", e.Button.Name, e.Button.Style));

                        break;

                }
            }
        }

        private void toolBar3_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            if (e.Button != null)
            {

                switch (e.Button.Style)
                {

                    case ToolBarButtonStyle.PushButton:

                        if (e.Button.Name == "toolBarButton7")
                        {    // Accompanying_stocks_open.cs
                            // show Accompanying_stocks user controls
                            //  MessageBox.Show(" show Accompanying_stocks user controls");
                            //this.panelStockManage.Controls.Clear();
                            ClearPanels();
                            if ((string)Session["isadmin"] == "true")
                            {

                                VisualWebGuiApplication2.ManagerControl objReports;

                                objReports = new ManagerControl();

                                this.panelmanager.Controls.Add(objReports);
                                this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                                this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                            }
                        }


                        if (e.Button.Name == "toolBarButton8")
                        {    // Accompanying_stocks_open.cs
                            // show Accompanying_stocks user controls
                            //  MessageBox.Show(" show Accompanying_stocks user controls");
                            //this.panelStockManage.Controls.Clear();
                              ClearPanels();
                              if ((string)Session["isadmin"] == "true")
                              {

                                  VisualWebGuiApplication2.SpecialOperation objReports;

                                  objReports = new SpecialOperation();

                                  this.panelmanager.Controls.Add(objReports);
                                  this.panelStockManage.Anchor = Gizmox.WebGUI.Forms.AnchorStyles.Right;
                                  this.panelStockManage.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
                              }
                        }
                        break;
                    default:
                        break;
                }
            }
        }



    }


    #region Random Data
  
    #endregion
}